package com.sctvcloud.dongqu.ui.adapter.holder;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;

import com.ruihang.generalibrary.ui.widget.CustomEXImageView;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.ruihang.generalibrary.utils.DateUtils;
import com.sctvcloud.dongqu.R;
import com.sctvcloud.dongqu.base.BaseActivity;
import com.sctvcloud.dongqu.beans.LiveItem;
import com.sctvcloud.dongqu.beans.TopicItem;
import com.sctvcloud.dongqu.ui.activities.LivingActivity;
import com.sctvcloud.dongqu.ui.activities.TopicDetailActivity;
import com.sctvcloud.dongqu.ui.utils.GlideUtil;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by yuxipan on 2017-11-14.
 */

public class SearchResultLiveHolder extends BaseSearchReultHolder<LiveItem> implements View.OnClickListener {

    @BindView(R.id.iv_search_live_item)
    protected CustomEXImageView img;
    //    @BindView(R.id.item_live_list_mode)
//    protected CustomFontTextView mode;
    @BindView(R.id.tv_search_item_title)
    protected CustomFontTextView title;
    @BindView(R.id.tv_live_tag_more)
    protected View vMore;

    @BindView(R.id.tv_search_item_time)
    protected CustomFontTextView date;
//    @BindView(R.id.item_live_label_channel)
//    protected CustomFontTextView channel;

    private LiveItem liveItem;

    public SearchResultLiveHolder(Context context, View itemView) {
        super(context, itemView);
        itemView.setOnClickListener(this);
    }

    @Override
    protected void initInject() {
        ButterKnife.bind(this, itemView);
    }

    @Override
    public void setData(LiveItem liveItem) {
        this.liveItem = liveItem;
//        if (liveItem.isLiving()) {
//            mode.setBackgroundResource(R.drawable.live_labei_bg);
//            mode.setText(R.string.livinging);
//        } else {
//            mode.setBackgroundResource(R.drawable.live_review_bg);
//            mode.setText(R.string.retrospect);
//        }
//        mode.setVisibility(View.GONE);
        title.setText(liveItem.getTitle());
        date.setText(DateUtils.formatDate(DateUtils.getDataDate(liveItem), ""));
//        channel.setText(liveItem.getChannelName());
        if (!TextUtils.isEmpty(liveItem.getLiveImg())) {
            GlideUtil.loadImgLarge169Def(context, liveItem.getLiveImg(), img);
        }
        vMore.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (internalClick != null) {
                    internalClick.onItemInternalClick(itemView, v, getAdapterPosition());
                }
            }
        });
        if (liveItem.isHasMore()) {
            vMore.setVisibility(View.VISIBLE);
        } else {
            vMore.setVisibility(View.GONE);
        }
    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent(context, LivingActivity.class);
//		if (liveItem != null && liveItem.isLiving()) {
        intent.putExtra(BaseActivity.EX_URL, liveItem.getLiveContentUrl());
        intent.putExtra(BaseActivity.EX_DATA, liveItem.getLiveImg());
//		}
        context.startActivity(intent);
    }
}
